package com.soft.line.controller;

import com.soft.line.service.LasUserInfoService;
import com.soft.line.service.UserConDepService;
import com.soft.line.util.exception.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(description = "用户合同部门相关接口")
@RestController
@RequestMapping("/systemAdmin")
public class UserConDepController {

    @Autowired
    private UserConDepService userConDepService;

    @Autowired
    private LasUserInfoService lasUserInfoService;

    @PostMapping("/userConDeps")
    @ApiOperation(value = "获取所有用户合同部门")
    public CommonResult getAllMenus(@RequestBody Map<String,Object> map) {
        return CommonResult.success(userConDepService.selectUserConDep(map));
    }

    @DeleteMapping("/userConDep")
    @ApiOperation(value = "删除用户合同部门")
    public CommonResult deleteRole(@RequestBody Map<String,Object> map) {
        userConDepService.delete(map);
        return CommonResult.success("删除成功");
    }

    @PostMapping("/role")
    @ApiOperation(value = "保存用户合同部门")
    public CommonResult saveRole(@RequestBody Map<String,Object> map) {
        if (map.get("userId")==null||"".equals(map.get("userId"))) {
            return CommonResult.failed("用户名称不能为空");
        }else{
            List<String> depList = (List<String>)map.get("depList");
            Integer userId=(Integer) map.get("userId");
            // 归档登记员可以看全部合同部门；
            if (lasUserInfoService.isAssistantManager(userId)){

            }else if (lasUserInfoService.isDepManager(userId)){
                // 总经理室的副总经理可以看两个合同部门；
            }else if (lasUserInfoService.isAssistantManager(userId)){
                // 部门经理可以看当前部门
                if (depList.size()!=1){
                    return CommonResult.failed("部门经理可以看当前部门");
                }
            }
            userConDepService.save(map);
            return CommonResult.success("保存成功");
        }
    }
}
